/**
 * Created by zhangqingxi on 2017/3/15.
 */


$(function () {

    initUseSate();
    //初始化下拉树
    $('#deptId').combotree({
        url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0',
        required: true
    });

    //表单提交
    $('#btn_save').on('click',function () {
        var index=layer.confirm('是否确定保存？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $('#form').form('submit', {
                url: ROOT_PATH+'/permission/post/edit.shtml',
                onSubmit: function (param) {
                    var isValid = $(this).form('validate');
                    if (!isValid) {
                        layer.close(index);
                        layer.msg("请正确填写表单")
                    }
                    return $(this).form('validate');
                },
                success: function (result) {
                    var data = $.parseJSON(result);

                    if(data.success){
                        window.parent.closeLayer(data);
                    }else{
                        layer.msg(data.message,{time:1000,icon:2});
                    }


                }
            });
        });

    });
    //参数清空
    $('#btn_reset').on('click',function () {
        $('#form').form('reset');
    });



});


//初始化是或否
function initUseSate() {
    var data=[{id:0,text:'停用'},{id:1,text:'启用'}];
    $('#useState').combobox({
        data:data,
        prompt:'请选择',
        required:true,
        editable:false,
        valueField:'id',
        textField:'text',
        panelHeight:'auto'
    });
}